﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ATW.MT.CommonClass;
using ATW.MT.BUS;
using System.Data;
using System.Text;

namespace ATW.MT.SellManage
{
    public partial class ApplyManage : CommonPage
    {
        bus_Supply_Range sr = new bus_Supply_Range();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }
        private void BindData()
        {
            string userName = txtName.Value.Trim();
            string type = ddlType.SelectedValue;
            string status = ddlStatus.SelectedValue;
            try
            {
                if (!common.filterChar(userName))
                {
                    Tips("查询条件中含有危险字符！");
                    return;
                }
                DataTable dt = sr.SpRangePagerQuery(userName, status, type, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize);
                if (dt != null && dt.Rows.Count > 0)
                {
                    AspNetPager1.RecordCount = Convert.ToInt32(dt.Rows[0]["TotalPagesize"]);
                }
                else
                {
                    AspNetPager1.RecordCount = 0;
                }
                rpList.DataSource = dt;
                rpList.DataBind();
            }
            catch (Exception ex)
            {

            }
        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
            BindData();
        }
        protected void AspNetPager1_pageChanged(object sender, EventArgs e)
        {
            BindData();
        }
        protected void lbnDeal_Click(object sender, EventArgs e)
        {
            LinkButton lbn = (LinkButton)sender;
            string SpRangeID = lbn.CommandArgument;
            Label lblName = (Label)lbn.Parent.FindControl("lblName");
            HiddenField hdfUid = (HiddenField)lbn.Parent.FindControl("hdfUid");
            try
            {
                int result = sr.SpRangeUpdate(SpRangeID, "3");
                if (result <= 0)
                {
                    Tips("处理失败!");
                    return;
                }
                else
                {
                    BindData();
                }
            }
            catch (Exception ex)
            {

            }
            string name = lblName.Text;
            string uid = hdfUid.Value;
            string url = "../SellManage/SupplyRange.aspx?uid=" + uid + "&n=" + name + "&r=" + new Random().Next(1000).ToString();
            OpenDialog("供货范围管理", url, "height=600,width=800");
        }
        private void Tips(string s)
        {//提示
            StringBuilder strScript = new StringBuilder();
            strScript.Append(@"<script language=javascript>
                var divTips=new jSharp.popUpDiv('divMsg');
                document.getElementById('msgContent').innerHTML='" + s + @"';
                divTips.Show();
                var t=setTimeout(function(){
                    divTips.Close();
                    clearTimeout(t);
                },1000);
            </script>");
            this.ClientScript.RegisterStartupScript(this.GetType(), "tips", strScript.ToString());
        }
    }
}